#pragma once

#include <iostream>
#include <ctime>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

namespace util 
{
    class Date {
        public:
            static size_t getTime() {
                return (size_t)time(nullptr);
            }
    };

    class File {
        public:
            static bool exists(const std::string &pathname) {
                struct stat st;
                if(stat(pathname.c_str(), &st) == 0) {
                    return true;
                }

                return false;
            }

            static std::string path(const std::string &pathname){
                size_t pos = pathname.find_last_of("/\\");
                if(pos == std::string::npos) {
                    return ".";
                }

                return pathname.substr(0, pos + 1);
            }

            static void createDirector(const std::string &pathname) {
                size_t pos = 0, begin = 0;
                while(begin < pathname.size()) {
                    pos = pathname.find_first_of("/\\", begin);
                    if(pos == std::string::npos) {
                        mkdir(pathname.c_str(), 0777);
                        break;
                    }
                    std::string parent_dir = pathname.substr(0, pos + 1);
                    if(!exists(parent_dir)) {
                        mkdir(parent_dir.c_str(), 0777);
                    }
                    begin = pos + 1;
                }
            }
    };
}